home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / read_spr.pro < prev    next >
Text File  |  1997-07-08  |  2KB  |  72 lines

  1. ;$Id: read_spr.pro,v 1.5 1997/01/15 03:11:50 ali Exp $
  2. ;
  3. ; Copyright (c) 1994-1997, Research Systems, Inc.  All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5. ;+
  6. ; NAME:
  7. ;       READ_SPR
  8. ;
  9. ; PURPOSE:
  10. ;       This function reads a row-indexed sparse matrix from a specified
  11. ;    file and returns it as the result.    Row-indexed sparse matrices
  12. ;    are created by using the Numerical Recipes routine NR_SPRSIN.
  13. ;
  14. ; CATEGORY:
  15. ;          Sparse Matrix File I/O    
  16. ;
  17. ; CALLING SEQUENCE:
  18. ;       result = READ_SPR('Filename')
  19. ;
  20. ; INPUTS:
  21. ;    Filename:  Name of file containing a row-indexed sparse matrix
  22. ;                  
  23. ; KEYWORD PARAMETERS;
  24. ;    NONE
  25. ;
  26. ; OUTPUTS:
  27. ;    result:  Row-indexed sparse matrix
  28. ;
  29. ;
  30. ; MODIFICATION HISTORY:
  31. ;       Written by:     BMH, 1/94.
  32. ;-
  33.  
  34. FUNCTION  READ_SPR, filename
  35.  
  36. ; result format = {sa:FLTARR(nmax) or sa:DBLARR(nmax), ija:LONARR(nmax)}
  37. ;
  38. nmax = 0L
  39. type = 0L
  40.  
  41. ON_IOERROR, BADFILE
  42.  
  43.  
  44. OPENR, fileLUN, filename, /GET_LUN
  45.  
  46. ;Read type and size information 
  47. READU, fileLUN, nmax, type
  48.  
  49. ;Define resulting structure based on the data size and type
  50. IF (type EQ 4) THEN $ ; Value array is single precision
  51.   result = {sa:FLTARR(nmax, /NOZERO),ija:LONARR(nmax, /NOZERO)} $
  52. else  $               ; Value array is double precision 
  53.   result = {sa:DBLARR(nmax, /NOZERO),ija:LONARR(nmax, /NOZERO)}
  54.  
  55. ;Read sparse matrix
  56. READU, fileLUN, result
  57.  
  58. FREE_LUN, fileLUN
  59.  
  60. RETURN, result
  61.  
  62.  
  63. BADFILE:
  64. IF (N_Elements(fileLUN) GT 0L) THEN $ 
  65.    FREE_LUN, fileLUN
  66. MESSAGE, 'Error reading sparse matrix file: ' + filename
  67.  
  68. END
  69.  
  70.  
  71.  
  72.